convert part 3

atom_to_float80

include convert.e 
namespace convert 
public function atom_to_float80(atom a) 

float80_to_atom

include convert.e 
namespace convert 
public function float80_to_atom(sequence bytes) 

atom_to_float32

include convert.e 
namespace convert 
public function atom_to_float32(atom a) 

converts an atom to a sequence of 4 bytes in IEEE 32-bit format.

Parameters:
  1. a : the atom to convert:
Returns:

A sequence, of 4 bytes, which can be poked in memory to represent a.

Comments:

Euphoria atoms can have values which are 64-bit IEEE floating-point numbers, so you may lose precision when you convert to 32-bits (16 significant digits versus 7). The range of exponents is much larger in 64-bit format (10 to the 308, versus 10 to the 38), so some atoms may be too large or too small to represent in 32-bit format. In this case you will get one of the special 32-bit values: inf or -inf (infinity or -infinity). To avoid this, you can use atom_to_float64.

Integer values will also be converted to 32-bit floating-point format.

On modern computers, computations on 64 bit floats are no slower than on 32 bit floats. Internally, the PC stores them in 80 bit registers anyway. Euphoria does not support these so called long doubles. Not all C compilers do.

Example 1:
fn = open("numbers.dat", "wb") 
puts(fn, atom_to_float32(157.82)) -- write 4 bytes to a file 
See Also:

float32_to_atom, int_to_bytes, atom_to_float64

float64_to_atom

include convert.e 
namespace convert 
public function float64_to_atom(sequence_8 ieee64) 

converts a sequence of 8 bytes in IEEE 64-bit format to an atom.

Parameters:
  1. ieee64 : the sequence to convert.
Returns:

An atom, the same value as the FPU would see by peeking ieee64 from RAM.

Comments:

Any 64-bit IEEE floating-point number can be converted to an atom.

Example 1:
f = repeat(0, 8) 
fn = open("numbers.dat", "rb")  -- read binary 
for i = 1 to 8 do 
    f[i] = getc(fn) 
end for 
a = float64_to_atom(f) 
See Also:

float32_to_atom, bytes_to_int, atom_to_float64

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu